﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace ru.yourpictures.Core.Imaging.Filters
{
    public class FilterCollection : List<IFilter>, IFilter, IDisposable
    {
        private bool disposed = false;

        #region IFilter Members

        public Bitmap Convert(Bitmap b)
        {
            Bitmap ret = new Bitmap(b);

            foreach (IFilter filter in this)
            {
                filter.Apply(ret);
            }

            return ret;
        }

        public void Apply(Bitmap b)
        {
            foreach (IFilter filter in this)
            {
                filter.Apply(b);
            }
        }

        #endregion

        #region IDisposable Members
        ~FilterCollection()
        {
        }
        /// <summary>
        /// Dispose the object
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            // Take yourself off of the Finalization queue 
            // to prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Object disposing routine
        /// </summary>
        /// 
        /// <param name="disposing"><b>True</b> if the method is called from
        /// <see cref="AForge.Imaging.Blob.Dispose()"/> method, <b>false</b> if the method is called
        /// from destructor.</param>
        /// 
        public void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // dispose managed resources
                    foreach (FilterBase filter in this)
                    {
                        filter.Dispose();
                    }
                }
            }
        }
        #endregion
    }
}
